package com.ahdy.pojo;

public class ResponseEntitys<T> {
    private static int status; // 状态码，如200、404等
    private String message; // 返回消息，如"操作成功"、"资源未找到"等
    private T data; // 返回的数据，可以是任意类型
    private int total;


    // 默认构造函数
    public ResponseEntitys() {
    }

    public ResponseEntitys(int status, String message, T data, int total) {
        this.status = status;
        this.message = message;
        this.data = data;
        this.total = total;
    }

    // Getter和Setter方法
    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 获取
     * @return total
     */
    public int getTotal() {
        return total;
    }

    /**
     * 设置
     * @param total
     */
    public void setTotal(int total) {
        this.total = total;
    }

    /**
     * 响应成功时
     * @param message
     * @param data
     * @param total
     * @return
     * @param <T>
     */
    public static <T> ResponseEntitys<T> success(String message, T data, int total) {
        return new ResponseEntitys<>(200,message,data,total);
    }

    /**
     * 响应失败时
     * @param message
     * @param data
     * @param total
     * @return
     * @param <T>
     */
    public static <T> ResponseEntitys<T> error(String message, T data, int total) {
        return new ResponseEntitys<>(400,message,data,total);
    }


    public String toString() {
        return
                "ResponseEntity{status = " + status + ", message = " + message + ", data = " + data + ", total = " + total + "}";
    }
}
